package com.tour.silvertour.Config;


import com.tour.silvertour.Common.Utils.Constant;
import com.tour.silvertour.Common.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Title: WebMvcConfig
 * @Author 苗桐菲
 * @Package com.tour.silvertour.Config
 * @Date 2024/3/31 14:08
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Value("${resturant.profile}")
    private String UPLOAD_FOLDER;
    /**
     * 注入自定义拦截器
     */
    @Resource
    private AuthInterceptor authInterceptor;

    /**
     * 配置拦截器和拦截、放行路径
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // excludePathPatterns放行路径，addPathPatterns拦截的路径
        registry.addInterceptor(authInterceptor)
                .excludePathPatterns("/api/user/login")
                .excludePathPatterns("/api/user/register")
                .addPathPatterns("/**");
    }
    /**
     * 求路径和服务器上的路径进行对应
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 本地文件上传路径 */
        registry.addResourceHandler(Constant.RESOURCE_PREFIX + "/**")
                .addResourceLocations("file:" + UPLOAD_FOLDER + "/");
    }
}
